package cn.bugio.note;

import cn.bugio.note.configuration.GlobalFeignConfiguration;
import cn.bugio.note.configuration.TestRestTemplateTokenRelayInterceptor;
import cn.bugio.note.rocketmq.MySource;
import cn.bugio.note.sentinel.GlobalSentinelBlock;
import cn.bugio.note.sentinel.GlobalSentinelFallback;
import com.alibaba.cloud.sentinel.annotation.SentinelRestTemplate;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.openfeign.EnableFeignClients;


import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;
import tk.mybatis.spring.annotation.MapperScan;

import java.util.Collections;


/**
 * @author Vincent Vic
 * @version 1.0
 * @Description
 * @since 2021/2/16
 */

@MapperScan("cn.bugio.note.dao.content")
@SpringBootApplication
@EnableFeignClients
//@EnableFeignClients(defaultConfiguration = GlobalFeignConfiguration.class)
@EnableDiscoveryClient
@EnableBinding(MySource.class) //stream

@Slf4j
public class ContentCenterApplication {
    public static void main(String[] args) {
        SpringApplication.run(ContentCenterApplication.class,args);
    }

    @Bean
    @LoadBalanced
    @SentinelRestTemplate
    public RestTemplate restTemplate(){
        RestTemplate restTemplate = new RestTemplate();
        restTemplate.setInterceptors(Collections.singletonList(
                new TestRestTemplateTokenRelayInterceptor()
        ));
        return restTemplate;
    }

    public static String block(String a, BlockException e){
        log.warn("限流或者降级 block",e);
        return "限流或者降级 block";
    }
}

